package com.sunday.common.leaf.study.operation;

/**
 * @Description: 62进制转换
 * @Author: zsy
 * @Create: 2022/12/29 16:39
 */
public class CompressEncoding62Utils {

    private static String characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String compressNumber(long number) {
        String ret = "";
        while (number > 0) {
            ret = characters.charAt((int) (number % 62)) + ret;
            number /= 62;
        }
        return ret;
    }

    public static long unCompressNumber(String compress) {
        long ret = 0;
        compress = new StringBuffer(compress).reverse().toString();
        long count = 1;
        for (char character : compress.toCharArray()) {
            ret += characters.indexOf(character) * count;
            count *= 62;
        }
        return ret;
    }

}
